﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CutAways.Modeling;
using CutAways.Geometry;
using Tao.OpenGl;

namespace CutAways.Shaders
{
    class BoxCutShader : ShaderHolder
    {
        bool status;

        public BoxCutShader(string[] vertexShaderFile, string[] fragmentShaderFile, string info)
        {
            base.LoadShaders(vertexShaderFile, fragmentShaderFile, info);
            status = false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="vertexArray">4 vertexy definujici BoundingBox</param>
        /// <param name="intervalArray">3 intervaly na osach BounddingBoxu</param>
        public bool SetParameters(Vertex[] vertexArray, Interval[] intervalArray)
        {
            if (vertexArray.Length != 4 || intervalArray.Length != 3)
                return false;

            Gl.glUseProgram(Program);

            int origin = Gl.glGetUniformLocation(Program, "origin");
            int uVertex = Gl.glGetUniformLocation(Program, "uVertex");
            int vVertex = Gl.glGetUniformLocation(Program, "vVertex");
            int wVertex = Gl.glGetUniformLocation(Program, "wVertex");

            int uMin = Gl.glGetUniformLocation(Program, "uMin");
            int uMax = Gl.glGetUniformLocation(Program, "uMax");
            int vMin = Gl.glGetUniformLocation(Program, "vMin");
            int vMax = Gl.glGetUniformLocation(Program, "vMax");
            int wMin = Gl.glGetUniformLocation(Program, "wMin");
            int wMax = Gl.glGetUniformLocation(Program, "wMax");

            Gl.glUniform3f(origin,  vertexArray[0].X, vertexArray[0].Y, vertexArray[0].Z);
            Gl.glUniform3f(uVertex, vertexArray[1].X, vertexArray[1].Y, vertexArray[1].Z);
            Gl.glUniform3f(vVertex, vertexArray[2].X, vertexArray[2].Y, vertexArray[2].Z);
            Gl.glUniform3f(wVertex, vertexArray[3].X, vertexArray[3].Y, vertexArray[3].Z);

            Gl.glUniform1f(uMin, intervalArray[0].Minimum);
            Gl.glUniform1f(uMax, intervalArray[0].Maximum);

            Gl.glUniform1f(vMin, intervalArray[1].Minimum);
            Gl.glUniform1f(vMax, intervalArray[1].Maximum);

            Gl.glUniform1f(wMin, intervalArray[2].Minimum);
            Gl.glUniform1f(wMax, intervalArray[2].Maximum);

            return true;
        }
    }
}
